package com.novel.web.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.novel.web.entity.NfNovel;
import com.novel.web.mapper.NfNovelMapper;
import com.novel.web.service.NfNovelService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 小说表
 *
 * @author 樊温军
 * @date Fri May 09 15:15:32 CST 2025
 */
@Slf4j
@Service
@AllArgsConstructor
public class NfNovelServiceImpl extends ServiceImpl<NfNovelMapper, NfNovel> implements NfNovelService {

    @Override
    public List<NfNovel> getNfNovelList(NfNovel nfNovel) {
        return baseMapper.getList(nfNovel);
    }

    @Override
    public IPage<NfNovel> getPage(Page<NfNovel> page, NfNovel nfNovel) {
        return baseMapper.getPage(page, nfNovel);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long saveOneNfNovel(NfNovel nfNovel) {
        this.saveOrUpdate(nfNovel);
        return nfNovel.getId();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delById(Long id) {
        baseMapper.delete(Wrappers.<NfNovel>query().lambda().in(NfNovel::getId, id));
    }

    @Override
    public NfNovel queryById(Long id) {
        return baseMapper.selectById(id);
    }
}
